//
//  TTImageTitleView.m
//  TaoTuo
//
//  Created by zhaoshijie on 2020/9/7.
//  Copyright © 2020 刘广. All rights reserved.
//

#import "TTImageTitleView.h"

@interface TTImageTitleView ()

@property (nonatomic, copy) NSString *leftImageName;
@property (nonatomic, copy) NSString *title;
@property (nonatomic, copy) NSString *rightImageName;

@property (nonatomic, strong) UIImageView *leftImageView;
@property (nonatomic, strong) UILabel *titleLabel;
@property (nonatomic, strong) UIImageView *rightImageView;

@end

@implementation TTImageTitleView

+ (instancetype)createViewWithLeftImageName:(NSString *)leftImageName title:(NSString *)title rightImageName:(NSString *)rightImageName
{
    TTImageTitleView *view = [[self alloc] init];
    view.leftImageName = leftImageName;
    view.rightImageName = rightImageName;
    view.title = title;
    [view setupSubviews];
    return view;
}

- (void)setupSubviews
{
    _titleLabel = [UILabel labelWithTitle:self.title color:UIColorHex(0x333333) font:[UIFont boldSystemFontOfSize:15]];
    [self addSubview:_titleLabel];
    [_titleLabel mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.bottom.centerX.equalTo(self);
    }];

    _leftImageView = [[UIImageView alloc] initWithImage:[UIImage imageNamed:self.leftImageName]];
    [self addSubview:_leftImageView];
    [_leftImageView mas_makeConstraints:^(MASConstraintMaker *make) {
        make.centerY.equalTo(self);
        make.right.equalTo(self.titleLabel.mas_left).mas_offset(-10);
    }];

    _rightImageView = [[UIImageView alloc] initWithImage:[UIImage imageNamed:self.rightImageName]];
    [self addSubview:_rightImageView];
    [_rightImageView mas_makeConstraints:^(MASConstraintMaker *make) {
        make.centerY.equalTo(self);
        make.left.equalTo(self.titleLabel.mas_right).mas_offset(10);
    }];
}

@end
